package mysql

import (
	"fmt"
	"gorm.io/gorm"
)

type User struct {
	gorm.Model
	Username string `gorm:"type:varchar(50);unique;comment：账户;"`
	Password string `gorm:"type:char(32);comment:密码;"`
	Sale     string `gorm:"type:char(5);comment:盐;"`
	Tel      string `gorm:"type:char(15);comment:手机号;"`
	Nickname string `gorm:"type:varchar(30);comment:昵称;"`
	Status   int8   `gorm:"type:tinyint(1);comment:状态 0正常 1 冻结;"`
}

// 创建用户
func (u *User) Reg() error {
	return DB.Create(&u).Error
}

// 查询用户
func (u *User) Log() error {
	return DB.Where("username = ?", u.Username).First(&u).Error
}

// 手机号登录
func (u *User) TelLog() error {
	err = DB.Where("tel = ?", u.Tel).First(&u).Error
	fmt.Println("查询到的数据........", u)
	return err
}

// 手机号查询
func (u *User) GetMobileInfo(mobile string) error {
	return DB.Where("tel = ?", mobile).First(&u).Error
}

// 账户查询
func (u *User) GetUsernameInfo(username string) error {
	return DB.Where("username = ?", username).First(&u).Error
}
